package com.fanchuan.uzx.list.detail;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.MotionEvent;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.fanchuan.uzx.R;
import com.googlecode.androidannotations.annotations.EActivity;
import com.googlecode.androidannotations.annotations.Extra;
import com.umeng.analytics.MobclickAgent;

@EActivity
public class DetailActivity extends SherlockFragmentActivity {
	public final static int EXTRA_MODE_NEWS = 1;
	public final static int EXTRA_MODE_OFFER = 2;
	public final static int EXTRA_MODE_LECTURE = 3;
	@Extra 
	long id;
	
	@Extra 
	String title;
	
	@Extra
	String time;
	
	@Extra
	int mode;
	String url;
	private static final String DETAIL_FRAGMENT = "DETAIL";
	private FragmentManager fm;
	Fragment fragment;
	
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		
		url = "http://s-50666.gotocdn.com/server4mobile/detail_api.php?id="+id;
		Log.d("detailUrl", url);
		
		fm = getSupportFragmentManager();
//		Fragment fragment = fm.findFragmentByTag(DETAIL_FRAGMENT);
		
		fragment = DetailInfoFragment_.builder().url(url).time(time).title(title).build();
		fm.beginTransaction().replace(android.R.id.content, fragment).commit();
	}

    @Override
    public boolean onTouchEvent(MotionEvent event) {
    	return ((DetailInfoFragment_)fragment).mDetector.onTouchEvent(event);
    }
    
    @Override
    public void onBackPressed() {
    	super.onBackPressed();
    	finish();
		overridePendingTransition(R.anim.base_slide_left_in,
				R.anim.base_slide_right_out);
    }
    
    
    @Override
    protected void onResume() {
    	String type ="";
    	if(mode == EXTRA_MODE_LECTURE){
    		type = "lecture";
    	}else if(mode == EXTRA_MODE_NEWS){
    		type = "news";
    	}else {
    		type = "offer"; 
    	}
    	MobclickAgent.onResume(this, "Detail", type);
    	super.onResume();
    }
}
